﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Collections;
using System.Drawing.Drawing2D;

namespace GDI_AnalysisComponents
{
    //鼠标按键提起类
    class GMouseUp
    {
        public GMouseUp()
        {
        }
        public string HandleGMouseUp(MouseEventArgs e, Control cl, GGraph ggraph,ListView ComponentListView)
        {
            string s = "";
            Graphics g = cl.CreateGraphics();
            PointF  mousePt = new PointF(e.X, e.Y);
            MouseEventMode mem = ggraph.MEM;
            cl.Invalidate();
            cl.Cursor = System.Windows.Forms.Cursors.Default;
            switch (mem)
            {
                case MouseEventMode.Normal:
                    s = null;
                    break;
                case MouseEventMode.LinkLine:                  
                    break;
                case MouseEventMode.AddComponent:
                    s = HandleAddComponnet(mousePt, ggraph, ComponentListView);
                    ggraph.MEM = MouseEventMode.Normal;
                    ggraph.GcSels.Clear();
                    break;        
                case MouseEventMode.SelectComponent:
                    ggraph.MEM = MouseEventMode.Normal;                    
                    break;
                case MouseEventMode.MoveComponent:
                    ggraph.MEM = MouseEventMode.Normal;
                    break;
                case MouseEventMode.TransformShape:
                    break;
                case MouseEventMode.SelLine:
                    break;
            }
            cl.Invalidate();
            return s;
        }

        //处理添加组件
        public string HandleAddComponnet(PointF mousePt, GGraph ggraph, ListView ComponentListView)
        {
            string s = null;
            for (int i = 0; i < ComponentListView.Items.Count; i++)
            {
                if (ComponentListView.Items[i].Selected == true)
                {
                    GComponent gc = ((GComponent)(ggraph.Gcs[i])).Clone(mousePt);
                    ggraph.GcSavs.Add(gc);
                    s = "你添加了组件"+gc.ID+gc.Name;
                }
            }
            return s;
        }
    }
}
